
const fs = require('fs');
const path = require('path');

const directoryPath = 'D:\\Repos\\www.gitee.com\\bim-viewer\\public\\_lib\\developer.api.autodesk.com\\modelderivative\\v2\\viewers\\7.73\\res';
let download_files = [];
const traverseFiles = (directoryPath, callback) => {
    fs.readdir(directoryPath, (err, files) => {
        if (err) {
            console.error(`Error reading directory: ${err.message}`);
            return;
        }

        files.forEach((file) => {
            const filePath = path.join(directoryPath, file);
            // 目录
            if (fs.statSync(filePath).isDirectory()) {
                traverseFiles(filePath, callback);
            }
            // 文件
            else {
                callback(filePath);
            }
        });
    });
}

function caclulateDirs() {
    traverseFiles(directoryPath, (filePath) => {
        filePath = filePath.replace(directoryPath, '');
        filePath = filePath.replaceAll('\\', '/');
        filePath = '.' + filePath;
        download_files.push(filePath);
    });
    setTimeout(() => {
        console.log(download_files);
    }, 2000)
}

caclulateDirs();